package com.lin.config;

import cn.hutool.bloomfilter.BitMapBloomFilter;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lin.domain.Chain;
import com.lin.domain.global.BitMap;
import com.lin.mapper.ChainMapper;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;

@Configuration
public class InitProjectConfig {
    @Resource
    private ChainMapper chainMapper;

    @PostConstruct
    public void init(){
        BitMapBloomFilter shortChainMap = BitMap.getShortChainMap();
        // 将短链都放到布隆过滤器中
        List<Chain> chains = chainMapper.selectList(new LambdaQueryWrapper<Chain>().select(Chain::getShortChain));
        for (Chain chain : chains) {
            shortChainMap.add(chain.getShortChain());
        }
    }
}
